<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>文档</title>
  <link href="./css/semantic/semantic.min.css" rel="stylesheet">
  <link href="./css/markdown.css" rel="stylesheet">

  <link href="./css/wtxynavigation.css" rel="stylesheet">
  <script src="./js/jquery.min.js"></script>
  <script type="text/javascript" src="./js/include.js"></script>
  <style>
    body{padding-top:0;background:#f7f7f7}
    body>.ui.container{width:100%;padding:0}
    #project-title{background:#6e6e6e;width:100%;line-height:3.572rem;color:#fff;font-size:1.2rem}
    #project-title .title-wrap{font-weight:700;padding:0 12px;width:100%;max-width:1366px!important;min-width:900px;margin:0 auto}
    #project-title .left,#project-title right{display:inline-block}
    #project-title .right{float:right}
    #project-title .right .wiki-actions .menu{left:auto;right:0;margin-top:.4em!important}
    #wiki-preview-container{width:100%;max-width:1366px!important;min-width:900px;padding:0;border:1px solid #e3e9ed;border-top:0}
    #wiki-preview>.ui.segment{margin-top:0;padding:1rem;padding-left:0;border:0}
    .hover-places{display:inline-block}
    #page-detail{width:60%;margin:0 auto}
    #page-detail .title{font-weight:700;font-size:24px;padding:12px 0;border-bottom:1px solid #ccc}
    #page-detail .content{margin-top:15px}
    .content p{word-wrap:break-word}
    #wiki-parent,#wiki-title,#wikis{display:none}
    .ui.grid{padding:0!important}
    #ex-all{cursor:pointer;color:#537c8d}
  </style>
</head>
<body>
  <div class="ui container">
    <div id="project-title">
      <div class="title-wrap">
        <div class="left">
          <i class="icon eye"></i>
          文档预览:
          mianmSDK
        </div>
        <div class="right">
          Export by Gitee
        </div>
      </div>
    </div>

    <div class="ui container" id="wiki-preview-container">
      <div id="wiki-preview">
        <div class="ui segment">
          <div id="page-detail" class="markdown-body">
            <div class='title'>opengl等比例显示图片</div><div class='content'><h1>
<a id="ios-opengl-怎样等比例显示画面" class="anchor" href="#ios-opengl-%E6%80%8E%E6%A0%B7%E7%AD%89%E6%AF%94%E4%BE%8B%E6%98%BE%E7%A4%BA%E7%94%BB%E9%9D%A2"></a>iOS opengl 怎样等比例显示画面?</h1>
<pre><code>
CAEAGLLayer : CALayer &lt;EAGLDrawable&gt;


</code></pre>
<p>CALayer与<code>contentMode</code>对应的属性叫做<code>contentsGravity</code>，但是它是一个NSString类型，而不是像对应的UIKit部分，那里面的值是枚举。<code>contentsGravity</code>可选的常量值有以下一些：</p>
<ul>
<li>kCAGravityCenter</li>
<li>kCAGravityTop</li>
<li>kCAGravityBottom</li>
<li>kCAGravityLeft</li>
<li>kCAGravityRight</li>
<li>kCAGravityTopLeft</li>
<li>kCAGravityTopRight</li>
<li>kCAGravityBottomLeft</li>
<li>kCAGravityBottomRight</li>
<li>kCAGravityResize</li>
<li>kCAGravityResizeAspect</li>
<li>kCAGravityResizeAspectFill</li>
</ul>
<p>和<code>cotentMode</code>一样，<code>contentsGravity</code>的目的是为了决定内容在图层的边界中怎么对齐，我们将使用kCAGravityResizeAspect，它的效果等同于UIViewContentModeScaleAspectFit， 同时它还能在图层中等比例拉伸以适应图层的边界。</p>
<pre><code>
self.layerView.layer.contentsGravity = kCAGravityResizeAspect;


</code></pre>
<h1>
<a id="答" class="anchor" href="#%E7%AD%94"></a>答:</h1>
<h3>
<a id="calayer-有个-和cotentmode一样contentsgravity的属性-设置这个属性可以调整显示" class="anchor" href="#calayer-%E6%9C%89%E4%B8%AA-%E5%92%8Ccotentmode%E4%B8%80%E6%A0%B7contentsgravity%E7%9A%84%E5%B1%9E%E6%80%A7-%E8%AE%BE%E7%BD%AE%E8%BF%99%E4%B8%AA%E5%B1%9E%E6%80%A7%E5%8F%AF%E4%BB%A5%E8%B0%83%E6%95%B4%E6%98%BE%E7%A4%BA"></a>CALayer 有个 和<code>cotentMode</code>一样，<code>contentsGravity</code>的属性, 设置这个属性可以调整显示</h3>
<h1>
<a id="扩展连接" class="anchor" href="#%E6%89%A9%E5%B1%95%E8%BF%9E%E6%8E%A5"></a>扩展连接</h1>
<p><a href="https://zsisme.gitbooks.io/ios-/content/chapter2/the-contents-image.html">iOS核心动画高级技巧-contentsGravity</a></p></div>
          </div>
        </div>
      </div>
      </div>
  </div>
</body>
</html>